package com.lin.Polymorphism;

public class da {
    public static void main(String[] args) {
        Animal animal = new Wolf();
        Animal animal1 = new Sleep();
        Wolf wolf1= new Wolf();
        animal.eat();
        if (wolf1 instanceof Animal){
            Animal animal3=(Animal) wolf1;
            animal3.show();
        }
        //父类多态无法调用子类特有方法
//        animal.cry();

        real( animal1);

            Wolf wolf = (Wolf) animal;
            wolf.cry();

        //编译看左,运行看右
//        Sleep sleep=(Sleep) animal;
    }

    public static void real(Animal animal){


        if (animal instanceof Wolf){
            Wolf wolf=(Wolf) animal;
            wolf.cry();
        }

        if (animal instanceof Sleep){
            Sleep sleep=(Sleep) animal;
            sleep.cry();
        }

    }
}
